home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Archive / Files / Standard File / StandardGetAlias / StandardGetAlias.c < prev    next >
Encoding:
Text File  |  2000-09-28  |  5.2 KB  |  157 lines  |  [TEXT/CWIE]

  1. /*
  2.  
  3.      File:        StandardGetAlias.c
  4.  
  5.      Contains:    Routines needed to use CustomGetFile for selecting alias
  6.                  files, rather than the original item the alias points to.
  7.  
  8.     Copyright:    © 1998-1999 by Apple Computer, Inc., all rights reserved
  9.  
  10.     Technology: Standard File dialogs
  11.     
  12.     Version:    1.0
  13.  
  14.     Bugs?:        For bug reports, consult the following page on
  15.                 the World Wide Web:
  16.  
  17.                     http://developer.apple.com/bugreporter/
  18.  
  19.     ========================================================================
  20.     You may incorporate this sample code into your applications without
  21.     restriction, though the sample code has been provided “AS IS” and the
  22.     responsibility for its operation is 100% yours.  However, what you are
  23.     not permitted to do is to redistribute the source as “DSC Sample Code”
  24.     after having made changes. If you’re going to re-distribute the source,
  25.     we require that you make it clear in the source that the code was
  26.     descended from Apple Sample Code, but that you’ve made changes.
  27.     ========================================================================
  28.  
  29.     A Few Notes:
  30.     
  31.     The routines in this file have been tested, though not exhaustively so.
  32.     They should not be used as the basis of the final code you use in your 
  33.     application without further testing.
  34.     
  35.     The error reporting is fairly complete, but there could be errors encounter 
  36.     which deserve a more descriptive message than is displayed here.
  37.     
  38.     This code assumes the presence of System 7 or later.  You should check
  39.     the system version before using these routines in your code.
  40.     
  41.     This routine uses CustomGetFile dialog, supplying custom filter and hook functions.
  42.     
  43.     The MoreFiles package is used for some of the sanity checking in the routines,
  44.     and is not included with this project.  You will need to obtain the 
  45.     MoreFiles package (from the developer ftp site) to build an use this project.
  46.     
  47.     Andy Bachorski - Apple Developer Technical Support (DTS)
  48.  
  49.     Writers:
  50.  
  51.         (afb)    Andy Bachorski
  52.  
  53.     Change History (most recent first):
  54.  
  55.          <1>      2/9/99    afb        first checked in
  56.  
  57. */
  58.  
  59. //******************    Universal Interfaces        ****************************
  60.  
  61. #include <Aliases.h>
  62. #include <Controls.h>
  63. #include <Folders.h>
  64. #include <Scrap.h>
  65. #include <StandardFile.h>
  66. #include <TextUtils.h>
  67. #include <ToolUtils.h>
  68.  
  69. // #include "MoreFilesExtras.h"
  70.  
  71.  
  72. //******************    Project Interfaces            ****************************
  73.  
  74. #include "StandardGetAlias.h"
  75.  
  76.  
  77. //******************    Private Definitions            ****************************
  78.  
  79. enum {
  80.     kFilterAllTypes            = -1,        // pass all types to filter proc in StandardFild get dialog
  81.     kUseStandardDialog        = 0
  82. };
  83.  
  84.  
  85. //******************    Private Prototypes            ****************************
  86.  
  87. pascal    Boolean    OnlyAliasFilesSFFilter( CInfoPBPtr myCInfoPBPtr, Ptr dataPtr );
  88. pascal    short    SFGetFolderDialogHook( short item, DialogPtr dialogPtr, Ptr dataPtr );
  89.  
  90.  
  91. //******************************************************************************
  92. //                                                                                
  93. //    This routine assumes the presence of CustomGetFile, which is available in    
  94. //    System 7 and later.  You should check for the right system version before    
  95. //    calling this routine.                                                        
  96. //                                                                                
  97. pascal void StandardGetAlias( StandardFileReply *sfReplyPtr )
  98. {
  99.     Point                 dialogTopLeft = { -1, -1 };        //    Use to center the dialog.    
  100.     SFTypeList            mySFTypeList = { 0 };
  101.     
  102.     FileFilterYDUPP        fileFilterUpp  = NewFileFilterYDProc( OnlyAliasFilesSFFilter );
  103.     DlgHookYDUPP        dialogHookUPP  = NewDlgHookYDProc( SFGetFolderDialogHook );
  104.     
  105.     //    Then display the custom choose folder dialog.    
  106.     
  107.     CustomGetFile( fileFilterUpp, kFilterAllTypes, mySFTypeList, sfReplyPtr, kUseStandardDialog, 
  108.                    dialogTopLeft, dialogHookUPP, nil, nil, nil, nil );
  109.                     
  110.     DisposeRoutineDescriptor( dialogHookUPP );
  111.     DisposeRoutineDescriptor( OnlyAliasFilesSFFilter );
  112.     
  113.     return;
  114. }//end StandardGetAlias
  115.  
  116. //******************************************************************************
  117. //                                                                                
  118. //    Return false (to display the item) if the item is a folder or alias file.    
  119. //                                                                                
  120. pascal Boolean OnlyAliasFilesSFFilter( CInfoPBPtr myCInfoPBPtr, Ptr dataPtr )
  121. {
  122. #pragma unused ( dataPtr )
  123.  
  124.     Boolean        isAlias = ( myCInfoPBPtr->hFileInfo.ioFlFndrInfo.fdFlags & kIsAlias ) != 0;
  125.     Boolean        isFolder = ( myCInfoPBPtr->hFileInfo.ioFlAttrib & ioDirMask ) != 0;
  126.     
  127.     //    Because the semantics of the filter proc are "true means don't show
  128.     //    it" the combined flags must be inverted before being returned.
  129.     
  130.     return !( isAlias  ||  isFolder );
  131. }//end OnlyAliasFilesSFFilter
  132.  
  133. //******************************************************************************
  134.  
  135. pascal short SFGetFolderDialogHook( short dialogItem, DialogPtr dialogPtr, Ptr dataPtr )
  136. {
  137. #pragma unused ( dataPtr )
  138.  
  139.     //    Sanity check first.  Be sure it's really a CustomGetFile dialog.    
  140.     
  141.     if ( ((WindowPeek)dialogPtr)->refCon == sfMainDialogRefCon )
  142.     {
  143.         //    sfHookOpenAlias is the only dialog item of interest.
  144.         //    To convince    CustomGetFile to return the FSSpec for the alias file, 
  145.         //    rather than its target item, simply return sfItemOpenButton as the
  146.         //    dialog item.                                            
  147.         if ( dialogItem == sfHookOpenAlias )
  148.         {
  149.             dialogItem = sfItemOpenButton;
  150.         }
  151.     }
  152.     
  153.     return dialogItem;
  154. }//end SFGetFolderDialogHook
  155.  
  156. //******************************************************************************
  157.